package com.wangxin.study8.threadtest;

/**
 * @author jojo.wang
 * @title: ReentrantLockQueueThreadTest
 * @projectName study8
 * @description: TODO
 * @date 2019/5/716:01
 */

public class ReentrantLockQueueThreadTest {
    public static void main(String[] args) {
        ReentrantLockQueueTest t = new ReentrantLockQueueTest();
        Thread put = new Thread(new ThreadQueuePut(t));
        put.start();
        Thread take = new Thread(new ThreadQueueTake(t));
        take.start();
    }
}

class ThreadQueuePut implements Runnable{
    private ReentrantLockQueueTest reentrantLockQueueTest;
    public ThreadQueuePut (ReentrantLockQueueTest reentrantLockQueueTest){
        this.reentrantLockQueueTest = reentrantLockQueueTest;
    }
    @Override
    public void run() {
        try {
            for (int i = 0; i < 100; i++) {
                reentrantLockQueueTest.put(i);
            }
        }catch (Exception e){

        }
    }
}
class ThreadQueueTake implements Runnable{
    private ReentrantLockQueueTest reentrantLockQueueTest ;
    public ThreadQueueTake (ReentrantLockQueueTest reentrantLockQueueTest){
        this.reentrantLockQueueTest = reentrantLockQueueTest;
    }
    @Override
    public void run() {
        try {
            for (int i = 0; i < 110; i++) {
                System.out.println("取出的值为："+reentrantLockQueueTest.take());
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}